//
//  LLWelcomeViewController.swift
//  新浪微博
//
//  Created by mac on 16/5/24.
//  Copyright © 2016年 mac.com. All rights reserved.
//

import UIKit
import SnapKit
//import 
class LLWelcomeViewController: UIViewController {
    override func loadView() {
       view = backImage
    }
    override func viewDidLoad() {
        super.viewDidLoad()
        setUpUI()
    }
    //设置约束
       private func setUpUI(){
        view.addSubview(icon)
        view.addSubview(nameLabel)
        
        
        icon.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(self.view.snp_centerX)
            make.bottom.equalTo(self.view.snp_bottom).offset(-160)
        }
        nameLabel.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(icon.snp_centerX)
            make.top.equalTo(icon.snp_bottom).offset(16)
        }
//        icon.setImageWithURL(LLUserAccountViewModel.sharedAccountViewModel.headURL)
        
        icon.cornerRadius = 45
        nameLabel.alpha = 0
        

    }
    override func prefersStatusBarHidden() -> Bool {
        return true
    }
    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)
        startAnimation()
    }
    //设置动画
    func startAnimation(){
    UIView.animateWithDuration(1.3, delay: 0, usingSpringWithDamping: 0.8, initialSpringVelocity: 1, options: [], animations: { () -> Void in
        let offset = -ScreenHeight + 160
        self.icon.snp_updateConstraints(closure: { (make) -> Void in
            make.bottom.equalTo(self.view.snp_bottom).offset(offset)
        })
        self.view.layoutIfNeeded()
        
        }) { (_) -> Void in
            UIView.animateWithDuration(0.4, animations: { () -> Void in
                self.nameLabel.alpha = 1
                }, completion: { (_) -> Void in
                 print("切换跟控制器")
                    NSNotificationCenter.defaultCenter().postNotificationName(SwitchRootViewController, object: "main")
            })
            
        }
    
    
    
    }
    //懒加载视图
   private lazy var icon = UIImageView(image: UIImage(named: "avatar_default_big"))
   private lazy var backImage = UIImageView(image: UIImage(named: "ad_background"))
   private lazy var nameLabel: UILabel = UILabel(title: "欢迎欢迎", font: 18, textColor: UIColor.darkGrayColor())
}
